package com.beordie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.beordie.dao.IImageDao;
import com.beordie.model.Image;
import com.beordie.model.Route;
import com.beordie.service.IImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Date 2021/8/7 8:56
 * @Created 30500
 */
@Service
public class ImageServiceImpl implements IImageService {
    @Autowired
    private IImageDao imageDao;

    @Override
    public List<Image> find() {
        return null;
    }

    @Override
    public int add(int routeId, List<String> smallList, List<String> bigList) {
        Image image = new Image();
        image.setRouteId(routeId);
        int result = 0;
        for (int i = 0; i < smallList.size(); i++) {
            image.setBigImage(bigList.get(i));
            image.setSmallImage(smallList.get(i));
            result += imageDao.insert(image);
        }
        return result;
    }


    @Override
    public List<Image> findByRouteId(int routeId) {
        QueryWrapper<Image> wrapper = new QueryWrapper<>();
        wrapper.eq("route_id", routeId);
        List<Image> imageList = imageDao.selectList(wrapper);
        return imageList;
    }

    @Override
    public int update(int routeId, List<String> smallList, List<String> bigList) {
        int delete = delete(routeId);
        int add = add(routeId, smallList, bigList);
        return add;
    }

    @Override
    public int delete(int routeId) {
        QueryWrapper<Image> wrapper = new QueryWrapper<>();
        wrapper.eq("route_id", routeId);
        int delete = imageDao.delete(wrapper);
        return delete;
    }
}
